/*
 * @Author: leo
 * @Date: 2024-10-18 13:47:31
 * @LastEditors: leo
 * @Description:
 */
import vue from '@vitejs/plugin-vue';
import { defineConfig } from 'vite';
import tailwindcss from 'tailwindcss';
import { visualizer } from 'rollup-plugin-visualizer';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    visualizer({
      filename: './dist/stats.html',
      title: 'Bundle Visualizer',
      open: true,
      gzipSize: true,
    }),
  ],
  css: {
    postcss: {
      plugins: [
        tailwindcss({
          content: ['./src/**/*.vue'],
        }),
      ],
    },
  },
  resolve: {
    alias: {
      'components': '/src/components',
    },
  },
  build:{
    rollupOptions: {
      // external: ['icon-site-group'], // 将整个库标记为外部依赖
      output: {
        manualChunks(id) {
          // 这里可以根据路径或名称来定义 chunk
          if (id.includes('node_modules')) {
            return id.split('node_modules/')[1].split('/')[0]; // 以库名为 chunk 名称
          }
        },
        globals: {
          'icon-site-group': 'IconSiteGroup', // 设置全局变量名称
        },
      },
    },
  }
});
